const { Controller, prefix, url, method, perform } = require('../../lib/controller')
const Auth = require('../../core/auth.js')

@prefix('/v1/user')
class User extends Controller {}

/**
 * 
 * @api {get} /v1/user/login 用户登录
 * @apiName login
 * @apiGroup user	
 * 
 * @apiParam  {String} paramName description
 * 
 * @apiSuccess (200) {type} name description
 * 
 * @apiParamExample  {type} Request-Example:
 * {
 *     property : value
 * }
 * 
 * @apiSuccessExample {type} Success-Response:
 * {
 *     property : value
 * }
 * 
 */
@url('/login')
@method('get')
class Index extends User {
	async handle() {
		let token = Auth.signToken('123456', Auth.USER)
		this.set('token', token)
		this.success('v1 test index' + Date.now())
	}
}

@url('/checktoken')
@method('get')
@perform(Auth.verify(Auth.USER))
class CheckToken extends User {
	async handle() {
		this.success('token is usefull')
	}
}

@url('/register')
@method('post')
class HaHa extends User {
	async handle() {
		this.body = { data: 'v1 test haha' }
	}
}

module.exports = { Index, HaHa, CheckToken }
